home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / ODF Release 3 / ODFDev / Clock / Sources / Frame.cpp < prev    next >
Encoding:
Text File  |  1996-12-16  |  7.3 KB  |  286 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Frame.cpp
  4. //    Release Version:    $ ODF 3 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FRAME_H
  11. #include "Frame.h"
  12. #endif
  13.  
  14. #ifndef PART_H
  15. #include "Part.h"
  16. #endif
  17.  
  18. #ifndef VIEW_H
  19. #include "View.h"
  20. #endif
  21.  
  22. #ifndef DEFINES_K
  23. #include "Defines.k"
  24. #endif
  25.  
  26. #ifndef CONTENT_H
  27. #include "Content.h"
  28. #endif
  29.  
  30. // ----- Part Layer -----
  31.  
  32. #ifndef FWUTIL_H
  33. #include "FWUtil.h"
  34. #endif
  35.  
  36. #ifndef FWITERS_H
  37. #include "FWIters.h"
  38. #endif
  39.  
  40. #ifndef FWCONTXT_H
  41. #include "FWContxt.h"
  42. #endif
  43.  
  44. #ifndef FWGROWBX_H
  45. #include "FWGrowBx.h"
  46. #endif
  47.  
  48. #ifndef FWSCLBAR_H
  49. #include "FWSclBar.h"
  50. #endif
  51.  
  52. // ----- OS Layer -----
  53.  
  54. #ifndef FWTXTSHP_H
  55. #include "FWTxtShp.h"
  56. #endif
  57.  
  58. #ifndef FWRECSHP_H
  59. #include "FWRecShp.h"
  60. #endif
  61.  
  62. #ifndef FWLINSHP_H
  63. #include "FWLinShp.h"
  64. #endif
  65.  
  66. #ifndef FWOVLSHP_H
  67. #include "FWOvlShp.h"
  68. #endif
  69.  
  70. #ifndef FWODGEOM_H
  71. #include "FWODGeom.h"
  72. #endif
  73.  
  74. #ifndef FWTXTBOX_H
  75. #include "FWTxtBox.h"
  76. #endif
  77.  
  78. #ifndef FWCFMRES_H
  79. #include "FWCFMRes.h"
  80. #endif
  81.  
  82. #ifndef FWRESACC_H
  83. #include "FWResAcc.h"
  84. #endif
  85.  
  86. #ifndef FWRESTYP_H
  87. #include "FWResTyp.h"
  88. #endif
  89.  
  90. #ifndef FWFXMATH_H
  91. #include "FWFxMath.h"
  92. #endif
  93.  
  94. #ifndef FWSCRCON_H
  95. #include "FWScrCon.h"
  96. #endif
  97.  
  98. #ifndef FWSUSINK_H
  99. #include "FWSUSink.h"
  100. #endif
  101.  
  102. #ifndef FWMNUBAR_H
  103. #include "FWMnuBar.h"
  104. #endif
  105.  
  106. //========================================================================================
  107. // RunTime information
  108. //========================================================================================
  109.  
  110. #ifdef FW_BUILD_MAC
  111. #pragma segment odfclock
  112. #endif
  113.  
  114. //========================================================================================
  115. // class CClockFrame
  116. //========================================================================================
  117.  
  118. FW_DEFINE_AUTO(CClockFrame)
  119.     
  120. //----------------------------------------------------------------------------------------
  121. // CClockFrame::CClockFrame
  122. //----------------------------------------------------------------------------------------
  123.  
  124. CClockFrame::CClockFrame(Environment* ev, ODFrame* odFrame, 
  125.                         FW_CPresentation* presentation, 
  126.                         CClockPart* clockPart,
  127.                         CClockContent* clockContent) :
  128.     FW_CFrame(ev, odFrame, presentation, clockPart),
  129.     fClockPart(clockPart),
  130.     fBackgroundColor(FW_kRGBWhite),
  131.     fClockContent(clockContent)
  132.  
  133. {
  134.     SetAdoptsContainerProperties(ev, TRUE);
  135.     
  136.     FW_DO_NOT_DEAD_STRIP(CAnalogView);
  137.     FW_DO_NOT_DEAD_STRIP(CDigitalView);
  138.     FW_DO_NOT_DEAD_STRIP(FW_CGrowBox);
  139.     
  140.     FW_END_CONSTRUCTOR
  141. }
  142.  
  143. //----------------------------------------------------------------------------------------
  144. // CClockFrame::~CClockFrame
  145. //----------------------------------------------------------------------------------------
  146.  
  147. CClockFrame::~CClockFrame()
  148. {
  149.     FW_START_DESTRUCTOR
  150. }
  151.  
  152. //----------------------------------------------------------------------------------------
  153. // CClockFrame::FacetAdded
  154. //----------------------------------------------------------------------------------------
  155.  
  156. void CClockFrame::FacetAdded(Environment* ev, ODFacet* facet, unsigned short facetCount)
  157. {
  158.     FW_CFrame::FacetAdded(ev, facet, facetCount);
  159.     
  160.     if (facetCount == 1)
  161.         this->UpdateUsedAndActiveShapes(ev);
  162. }
  163.         
  164. //----------------------------------------------------------------------------------------
  165. // CClockFrame::Draw
  166. //----------------------------------------------------------------------------------------
  167.  
  168. void CClockFrame::Draw(Environment* ev, ODFacet* odFacet, ODShape* invalidShape)
  169. {    
  170.     // [HLX] This will be moved into an erase adorner
  171.     if (IsRoot(ev))
  172.     {
  173.         FW_CViewContext vc(ev, this, odFacet, invalidShape);
  174.  
  175.         FW_CRect invalidRect;
  176.         vc.GetClipRect(invalidRect);
  177.  
  178. #ifdef FW_BUILD_MAC
  179.         FW_CInk ink(FW_kRGBWhite,
  180.                     FW_kRGBWhite,
  181.                     FW_kErase);
  182. #else
  183.         FW_CInk ink(FW_CColor(::GetSysColor(COLOR_WINDOWTEXT), 0),
  184.                     FW_CColor(::GetSysColor(COLOR_APPWORKSPACE), 0),
  185.                     FW_kErase);
  186. #endif
  187.         FW_CRectShape::RenderRect(vc, invalidRect, FW_kFill, ink);
  188.     }
  189. }
  190.  
  191. //----------------------------------------------------------------------------------------
  192. //    CClockFrame::PresentationChanged
  193. //----------------------------------------------------------------------------------------
  194.  
  195. void CClockFrame::PresentationChanged(Environment* ev)
  196. {
  197.     FW_CFrame::PresentationChanged(ev);
  198.  
  199.     UpdateUsedAndActiveShapes(ev);
  200. }
  201.  
  202. //----------------------------------------------------------------------------------------
  203. //    CClockFrame::SetBackgroundColor
  204. //----------------------------------------------------------------------------------------
  205.  
  206. void CClockFrame::SetBackgroundColor(Environment* ev, FW_CColor& newColor)
  207. {
  208.     if (newColor != fBackgroundColor)
  209.     {
  210.         fBackgroundColor = newColor;
  211.         Invalidate(ev);
  212.     }
  213. }
  214.  
  215. //----------------------------------------------------------------------------------------
  216. //    CClockFrame::GetBackgroundColor
  217. //----------------------------------------------------------------------------------------
  218.  
  219. void CClockFrame::GetBackgroundColor(FW_CColor* newColor) const
  220. {
  221.     *newColor = fBackgroundColor;
  222. }
  223.  
  224. //----------------------------------------------------------------------------------------
  225. //    CClockFrame::AdjustUsedShape
  226. //----------------------------------------------------------------------------------------
  227. //    'suggestedUsedShape' is equal to the frame shape
  228.  
  229. ODShape* CClockFrame::AdjustUsedShape(Environment* ev, ODShape* suggestedUsedShape)
  230. {    
  231.     FW_ASSERT(GetViewType(ev) == FW_CPart::fgViewAsFrameToken);
  232.         
  233.     FW_CRect usedRect = FW_GetShapeBoundingBox(ev, suggestedUsedShape);
  234.  
  235.     CClockView* clockView = GetClockView(ev);
  236.     if (clockView == NULL)
  237.         return FW_CFrame::AdjustUsedShape(ev, suggestedUsedShape);
  238.     else    
  239.         return clockView->CreateUsedShape(ev, usedRect);
  240. }
  241.  
  242. //----------------------------------------------------------------------------------------
  243. //    CClockFrame::AdjustActiveShape
  244. //----------------------------------------------------------------------------------------
  245. //    [HLX] Because OpenDoc uses the Frame shape as the default active shape I need to 
  246. //    adjust my active shape too.
  247.  
  248. ODShape* CClockFrame::AdjustActiveShape(Environment* ev, ODFacet* facet, ODShape* suggestedActiveShape)
  249. {
  250. FW_UNUSED(facet);
  251.     FW_ASSERT(GetViewType(ev) == FW_CPart::fgViewAsFrameToken);
  252.  
  253.     suggestedActiveShape->Acquire(ev);
  254.     return suggestedActiveShape;
  255. }
  256.  
  257. //----------------------------------------------------------------------------------------
  258. //     CClockFrame::AdoptContainingPartProperties
  259. //----------------------------------------------------------------------------------------
  260.  
  261. void CClockFrame::AdoptContainingPartProperties(Environment* ev, 
  262.                                                 ODStorageUnit* propertyUnit)
  263. {
  264.     FW_CColor newColor = FW_kRGBWhite;
  265.     
  266.     if (fClockContent->UsesContainerColor() && propertyUnit && propertyUnit->Exists(ev, kBackgroundColorProp, kBackgroundColorValue, 0))
  267.     {
  268.         FW_PStorageUnitSink suSink(ev, propertyUnit, kBackgroundColorProp, kBackgroundColorValue);
  269.         FW_PBufferedSink sink(ev, suSink);
  270.         FW_CReadableStream stream(sink);
  271.         
  272.         stream >> newColor;
  273.     }
  274.     
  275.     SetBackgroundColor(ev, newColor);
  276. }
  277.  
  278. //----------------------------------------------------------------------------------------
  279. //     CClockFrame::GetClockView
  280. //----------------------------------------------------------------------------------------
  281.  
  282. CClockView* CClockFrame::GetClockView(Environment* ev) const
  283. {
  284.     return (CClockView*)FindViewByID(ev, kClockViewID);
  285. }
  286.